VS Code添加注释详细解决方法:VS Code 如何自动快速添加头部注释,及函数注释(以python添加 #!/usr/bin/env python # coding=utf

您所在的位置:网站首页 HTML 添加注释 VS Code添加注释详细解决方法:VS Code 如何自动快速添加头部注释,及函数注释(以python添加 #!/usr/bin/env python # coding=utf

VS Code添加注释详细解决方法:VS Code 如何自动快速添加头部注释,及函数注释(以python添加 #!/usr/bin/env python # coding=utf

2023-09-28 20:54| 来源: 网络整理| 查看: 265

VS Code添加注释详细解决方法:VS Code 如何自动快速添加头部注释,及函数注释(以python添加 #!/usr/bin/env python # coding=utf-8为例)

文章目录 VS Code添加注释详细解决方法:VS Code 如何自动快速添加头部注释,及函数注释(以python添加 #!/usr/bin/env python # coding=utf-8为例)方法1方法2效果:

方法1 在VSCode左下角齿轮那里选择user snippets出来以后选pythonJSON里面加下面这一段然后在.py文件输入header就会变成这个文件头了 "header of user":{ "prefix": "header", "body": [ "#!/usr/bin/python", "# -*- encoding: utf-8 -*-", "#@File : $TM_FILENAME", "#@Time : $CURRENT_YEAR/$CURRENT_MONTH/$CURRENT_DATE $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND", "#@Author : Orange ", "#@Email: [email protected]", "", //"# here put the import lib", "$0" ], "description": "Add the above information to the head " } 方法2

也可以使用Filehead插件 在这里插入图片描述

安装完成后,重启vs code 然后 打开设置 在这里插入图片描述 在这里插入图片描述

文件头部注释:Fileheader:custom Made函数注释:Fileheader:cursor Mode

这两个随便选一个 Edit in settings.json 将内容全选替换为下面的代码 (我没用到的方法被我注释掉了,大家要是有需要可以自行取消注释)

{ "go.formatTool": "goimports", "editor.renderControlCharacters": true, "go.docsTool": "gogetdoc", "go.useLanguageServer": true, "files.autoGuessEncoding": true, "workbench.iconTheme": "vscode-icons", "editor.copyWithSyntaxHighlighting": false, // 文件头部注释 "fileheader.customMade": { "Author":"Orange", //作者 "Date":"Do not edit", //创建时间 //"LastEditors":"", //最终修改者 "FilePath": "Do not edit", "Email":"[email protected]", "LastEditTime": "Do not edit" //最终修改时间 }, //函数注释 "fileheader.cursorMode": { "name":"", "test":"test font", "msg":"", "param":"", "return":"" }, // 设置 自动添加的注释头或函数注释都是 "fileheader.configObj": { "createHeader": true, // 默认打开 新建文件自动添加头部注释 "autoAdd": true, // 自动添加头部注释开启才能自动添加,开启该选项之后,插件会检测当前保存的文件有没有头部注释,如果没有的话,将为自动添加头部注释(就像你按了头部注释的快捷键一样)。 "autoAlready": true, // 自动添加头部注释:只允许插件支持的语言,以及用户通过language 选项自定义的注释 "wideSame": true, // 设置为true开启 //"wideNum": 13, // 字段长度 默认为13 "autoAddLine": 100, // 默认文件超过100行就不再自动添加头部注释 "beforeAnnotation": { "py": "#!/usr/bin/env python\n# coding=utf-8", // 在py,可以根据需求修改,在头部注释前面插入内容 //"*": "\n" // 所有文件的头部注释都在前面增加一个换行(除了py) }, "language": { // 普通后缀文件 "py": { "head": "#@Information:", "middle": "#@", "end": "\n" }, // 一次匹配多种文件后缀文件 不用重复设置 "h/hpp/cpp": { "head": "/*** ", // 统一增加几个*号 "middle": " * @", "end": " */" }, // 针对有特殊要求的文件如:test.blade.php "blade.php":{ "head": "", } } // "afterAnnotation": { // "js": "// js文件头部注释之后的内容", // "*": "\n" // 所有文件新增头部注释之后都空一行(除了js) // }, // 需要特殊定制的文件后缀 // "headInsertLine": { // "php": 2, // php后缀的文件,在第二行插入文件头部注释 // "*": 3, // 所有文件都在第3行插入注释(除了php) // }, //"prohibitAutoAdd": [ "json", "md" ], // 禁止.json .md文件,自动添加头部注释 } }

然后在.py文件中按ctrl +alt +i即可添加注释,官方说明如下 在这里插入图片描述 注意:Fileheader的自动添加功能需要设置完后重启vs code

效果:

在这里插入图片描述 希望本篇文章可以帮助到各位小伙伴呀



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3